package com.health.manage.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.health.manage.mapper.*;
import com.health.manage.pojo.dto.AssessDto;
import com.health.manage.pojo.entity.*;
import com.health.manage.service.IAssessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;


/**
 * @Description: 健康评估业务处理
 * @author: user
 */
@Service
public class AssessServiceImpl extends ServiceImpl<AssessMapper, Assess> implements IAssessService {

    @Autowired(required = false)
    private AssessMapper assessMapper;
    @Autowired(required = false)
    private UserMapper userMapper;
    @Autowired(required = false)
    private PhysicalMapper physicalMapper;
    @Autowired(required = false)
    private MulesMapper mulesMapper;

    @Autowired(required = false)
    private FemaleMulesMapper femaleMulesMapper;

    @Override
    public Boolean addData(Assess assess) {
        int result = this.assessMapper.insert(assess);
        if (result > 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Boolean updateData(Assess assess) {
        int result = this.assessMapper.updateById(assess);
        if (result > 1) {
            return true;
        } else {
            return false;
        }
    }


    @Override
    public Boolean deleteData(Long id) {
        int result = this.assessMapper.deleteById(id);
        if (result > 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Page<Assess> getPageData(AssessDto assessDto) {

        Page<Assess> page = new Page<>(assessDto.getCurrentPage(), assessDto.getPageSize());
        QueryWrapper<Assess> queryWrapper = new QueryWrapper<>();
        if (assessDto.getUserId() != null && !"".equals(assessDto.getUserId())) {
            queryWrapper.eq("user_id", assessDto.getUserId());
        }
        if (assessDto.getScore() != null && !"".equals(assessDto.getScore())) {
            queryWrapper.like("score", assessDto.getScore());
        }
        if (assessDto.getAccount() != null && !"".equals(assessDto.getAccount())) {
            queryWrapper.apply("user_id in(select id from user where account like {0} )", "%" + assessDto.getAccount() + "%");
        }
        Page<Assess> records = this.assessMapper.selectPage(page, queryWrapper);
        for (Assess assess : records.getRecords()) {
            User user = this.userMapper.selectById(assess.getUserId());
            if (user != null) {
                assess.setUser(user);
            }
            User creator = this.userMapper.selectById(assess.getCreateId());
            if (creator != null) {
                assess.setCreator(creator);
            }
        }
        return records;
    }


    @Override
    public JSONObject getScoreData(AssessDto assessDto) {

        JSONObject jsonObject = new JSONObject();
        int score = 0;
        StringBuffer stringBuffer = new StringBuffer();
        try {
            // 获取最新身高指标
            QueryWrapper<Physical> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("user_id", assessDto.getUserId());
            queryWrapper.orderByDesc("id");
            List<Physical> records = this.physicalMapper.selectList(queryWrapper);
            if (records.size() > 0) {
                Physical physical = records.get(0);
                //身高
                String height = physical.getHeight();
                //体重
                String weight = physical.getWeight();
                //计算体脂
                {
                    DecimalFormat df = new DecimalFormat("0.00");//设置保留位数
                    double h = Double.parseDouble(df.format((double) Integer.parseInt(height) / 100));
                    double bmi = Double.valueOf(weight) / (h * h);
                    BigDecimal b = new BigDecimal(bmi);
                    double d = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();

                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "体指");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", d);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //低压
                String lowPressure = physical.getLowPressure();
                {
                    int d = Integer.parseInt(lowPressure);

                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "低压");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", d);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }
                //高压
                String highPressure = physical.getHighPressure();
                {
                    int d = Integer.parseInt(highPressure);

                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "高压");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", d);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }
                //血糖
                String glucose = physical.getGlucose();
                {
                    BigDecimal b = new BigDecimal(glucose);
                    double d = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "血糖");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", d);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }
                //心率
                String heart = physical.getHeart();
                {
                    int d = Integer.parseInt(heart);

                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "心率");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", d);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }

// 获取用户性别
                User user = userMapper.selectById(assessDto.getUserId());
// 计算红细胞
                String erythrocyte = physical.getErythrocyte();
                Double erythrocyteD = Double.valueOf(erythrocyte);
// 根据性别选择不同的查询条件和操作
                if (user.getSex() == 0) {
                    // 男生分支的查询条件和操作
                    System.out.println(user.getSex());
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "红细胞");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", erythrocyteD);
                    // 处理男生数据...
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                } else if (user.getSex() == 1) {
                    // 女生分支的查询条件和操作
                    QueryWrapper<FemaleMules> maleQueryWrapper = new QueryWrapper<>();
                    maleQueryWrapper.eq("name", "红细胞");
                    maleQueryWrapper.apply("min_score<={0} and max_score>={0}", erythrocyteD);
                    // 处理女生数据...
                    List<FemaleMules> maleDataList = femaleMulesMapper.selectList(maleQueryWrapper);
                    if (maleDataList.size() > 0) {
                        FemaleMules mules = maleDataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算血红蛋白
                String hemoglobin = physical.getErythrocyte();
                Double hemoglobinD = Double.valueOf(hemoglobin);
                // 根据性别选择不同的查询条件和操作
                if (user.getSex() == 0) {
                    // 男生分支的查询条件和操作
                    System.out.println(user.getSex());
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "血红蛋白");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", hemoglobinD);
                    // 处理男生数据...
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                } else if (user.getSex() == 1) {
                    // 女生分支的查询条件和操作
                    QueryWrapper<FemaleMules> maleQueryWrapper = new QueryWrapper<>();
                    maleQueryWrapper.eq("name", "血红蛋白");
                    maleQueryWrapper.apply("min_score<={0} and max_score>={0}", hemoglobinD);
                    // 处理女生数据...
                    List<FemaleMules> maleDataList = femaleMulesMapper.selectList(maleQueryWrapper);
                    if (maleDataList.size() > 0) {
                        FemaleMules mules = maleDataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算白细胞
                String leukocyte = physical.getLeukocyte();
                {
                    Double leukocyteD = Double.valueOf(leukocyte);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "白细胞");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", leukocyteD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }

                //计算中粒细胞
                String Neutrophils = physical.getLeukocyte();
                {
                    Double NeutrophilsD = Double.valueOf(Neutrophils);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "中粒细胞");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", NeutrophilsD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }

                //计算淋巴细胞
                String lymphocyte = physical.getLeukocyte();
                {
                    Double lymphocyteD = Double.valueOf(lymphocyte);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "淋巴细胞");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", lymphocyteD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算血小板
                String platelet = physical.getLeukocyte();
                {
                    Double plateletD = Double.valueOf(platelet);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "血小板");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", plateletD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }
                //计算总胆固醇
                String total_cholesterol = physical.getLeukocyte();
                {
                    Double total_cholesterolD = Double.valueOf(total_cholesterol);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "总胆固醇");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", total_cholesterolD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算甘油三酯
                String Triglycerides = physical.getLeukocyte();
                {
                    Double TriglyceridesD = Double.valueOf(Triglycerides);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "甘油三酯");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", TriglyceridesD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算低密度脂蛋白胆固醇
                String LDL_cholesterol = physical.getLeukocyte();
                {
                    Double LDL_cholesterolD = Double.valueOf(LDL_cholesterol);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "低密度脂蛋白胆固醇");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", LDL_cholesterolD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }
                //计算高密度脂蛋白胆固醇
                String HDL_cholesterol = physical.getLeukocyte();
                {
                    Double HDL_cholesterolD = Double.valueOf(HDL_cholesterol);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "高密度脂蛋白胆固醇");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", HDL_cholesterolD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }
                //计算谷丙转氨酶
                String alanine_transaminase = physical.getLeukocyte();
                {
                    Double alanine_transaminaseD = Double.valueOf(alanine_transaminase);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "谷丙转氨酶");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", alanine_transaminaseD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }
                //计算谷草转氨酶
                String aspartate_aminotransferase = physical.getLeukocyte();
                {
                    Double aspartate_aminotransferaseD = Double.valueOf(aspartate_aminotransferase);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "谷草转氨酶");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", aspartate_aminotransferaseD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }
                //计算总胆红素
                String total_bilirubin = physical.getLeukocyte();
                {
                    Double total_bilirubinD = Double.valueOf(total_bilirubin);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "总胆红素");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", total_bilirubinD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算直接胆红素
                String total_bilirubin_direct = physical.getLeukocyte();
                {
                    Double total_bilirubin_directD = Double.valueOf(total_bilirubin_direct);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "直接胆红素");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", total_bilirubin_directD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }


                //计算尿蛋白
                String pro = physical.getPro();
                {
                    Double proD = Double.valueOf(pro);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "尿蛋白");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", proD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算尿葡萄糖
                String glu = physical.getGlu();
                {
                    Double gluD = Double.valueOf(glu);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "尿葡萄糖");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", gluD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算尿胆红素
                String bil = physical.getBil();
                {
                    Double bilD = Double.valueOf(bil);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "尿胆红素");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", bilD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }
                //计算尿胆胴体
                String ket = physical.getKet();
                {
                    Double ketD = Double.valueOf(ket);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "尿酮体");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", ketD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                } //计算白细胞(/HP)
                String wbc = physical.getWbc();
                {
                    Double wbcD = Double.valueOf(wbc);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "白细胞(/HP)");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", wbcD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                } //计算红细胞(/HP)
                String rbc = physical.getRbc();
                {
                    Double rbcD = Double.valueOf(rbc);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "红细胞(/HP)");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", rbcD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算尿胆原
                String uro = physical.getUro();
                {
                    Double uroD = Double.valueOf(uro);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "尿胆原");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", uroD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        String result = mules.getResult();
                        String suggest = mules.getSuggest();
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");
                    }
                }

                //计算尿比重
                String sg = physical.getSg();
                {
                    Double sgD = Double.valueOf(sg);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "尿比重");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", sgD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }

                //计算尿酸碱度
                String ph = physical.getPh();
                {
                    Double phD = Double.valueOf(ph);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "尿酸碱度");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", phD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                } //计算甲胎蛋白
                String afp = physical.getAfp();
                {
                    Double afpD = Double.valueOf(afp);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "甲胎蛋白");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", afpD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }
                //计算癌胚抗原
                String cea = physical.getCea();
                {
                    Double ceaD = Double.valueOf(cea);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "癌胚抗原");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", ceaD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }
                //计算铁蛋白
                String fer = physical.getFer();
                {
                    Double ferD = Double.valueOf(fer);
                    QueryWrapper<Mules> mulesQueryWrapper = new QueryWrapper<>();
                    mulesQueryWrapper.eq("name", "铁蛋白");
                    mulesQueryWrapper.apply("min_score<={0} and max_score>={0}", ferD);
                    List<Mules> dataList = mulesMapper.selectList(mulesQueryWrapper);
                    if (dataList.size() > 0) {
                        Mules mules = dataList.get(0);
                        score += mules.getScore();
                        stringBuffer.append(mules.getName() + "：" + mules.getResult() + "， ");

                    }
                }

                jsonObject.put("score", score);
                jsonObject.put("result", stringBuffer.toString());

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonObject;
    }


}
